package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.Webuser;
import com.ruoyi.system.domain.BUser;
import com.ruoyi.system.domain.vo.BUserVo;
import com.ruoyi.system.service.BUserService;
import com.ruoyi.system.mapper.BUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
* @author yangxingze
* @description 针对表【b_user(用户表)】的数据库操作Service实现
* @createDate 2024-10-11 23:30:56
*/
@Service
public class BUserServiceImpl extends ServiceImpl<BUserMapper, BUser>
    implements BUserService{

    /**
     * 根据条件查询用户列表
     * @param bUser
     * @return
     */
    @Override
    public List<BUserVo> selectUserList(BUser bUser) {
        return baseMapper.selectUserList(bUser);
    }

    /**
     * 根据医生Id获取详细信息
     * @param userId
     * @return
     */
    @Override
    public BUserVo selectUserById(Long userId) {
        return baseMapper.selectUserById(userId);
    }

    /**
     * 根据username查询用户
     * @param userName 用户名
     * @return
     */
    @Override
    public Webuser selectUserByUserName(String userName) {
        BUser user = this.getOne(new QueryWrapper<BUser>().lambda().eq(BUser::getName, userName));
        if(ObjectUtils.isEmpty(user)){
            return null;
        }
        Webuser webuser = new Webuser();
        BeanUtils.copyProperties(user,webuser);
        return webuser;
    }

    /**
     * 通过微信openId查询用户
     * @param openId
     * @return
     */
    @Override
    public BUser selectUserByOpenId(String openId) {
        BUser user = this.getOne(new QueryWrapper<BUser>().lambda().eq(BUser::getOpenid, openId));
        if(ObjectUtils.isEmpty(user)){
            return null;
        }
        return user;
    }

    /**
     * 通过手机号查询用户
     * @param mobile
     * @return
     */
    @Override
    public BUser selectUserByMobile(String mobile) {
        BUser user = this.getOne(new QueryWrapper<BUser>().lambda().eq(BUser::getMobile, mobile));
        if(ObjectUtils.isEmpty(user)){
            return null;
        }
        return user;
    }

    /**
     * 删除医生
     * @param userIds
     * @return
     */
    @Override
    public int deleteUserByIds(Long[] userIds) {
        return baseMapper.deleteUserByIds(userIds);
    }

    /**
     * 获取用户总积分
     * @param userId
     * @return
     */
    @Override
    public Integer getTotalScores(Long userId) {
        return baseMapper.getTotalScores(userId);
    }

    /**
     * 根据项目获取医生统计信息
     * @param projectId
     * @return
     */
    @Override
    public List<BUserVo> selectUserDataByProjectId(Long projectId) {
        return baseMapper.selectUserDataByProjectId(projectId);
    }
}




